package gui.arp;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.AbstractCellEditor;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

@SuppressWarnings("serial")
public class ArpCellEditor extends AbstractCellEditor implements
		TableCellEditor {
	private JLabel lblTune;
	private ArpCellEditorMouseAdapter mouseAdapter;
	
	public ArpCellEditor(Color fgColor, Font font) {
		super();
		
		lblTune = new JLabel();
		lblTune.setForeground(fgColor);
		lblTune.setFont(font);
		lblTune.setHorizontalAlignment(JLabel.CENTER);
		
		mouseAdapter = new ArpCellEditorMouseAdapter();
		lblTune.addMouseMotionListener(mouseAdapter);
	}

	@Override
	public Object getCellEditorValue() {
		return lblTune.getText();
	}

	@Override
	public Component getTableCellEditorComponent(JTable table, Object value,
			boolean isSelected, int row, int column) {
		System.out.println("getTableCellEditorComponent()");

		if (row == 1) {
			lblTune.setText((String) value);
			mouseAdapter.resetLastPos();
			return lblTune;
		}
		return null;
	}
}
